<template>
    <scroll-view class="video_main"
                 scroll-y
                 enable-flex
                 @scrolltolower="handleToLower"
    >
        <view class="video_item" v-for="(item,i) in videolist" :key="i" @click="handleGoVideo(item,i)">
            <img mode="widthFix" :src="item.img" alt="" >
        </view>

    </scroll-view>
</template>

<script>
    export default {
        name: "index",
        data() {
            return {
                videolist: [],
                hasMore: true
            }
        },
        props: {
            urlobj: Object,

        },
        mounted() {
            // console.log(this.urlobj)
            this.getList()
        },
        // 监听 组件 数据变化
        watch: {
            urlobj() {
                this.videolist = [];
                // console.log('参数发生变化');
                // console.log(this.urlobj)
                this.getList()
            }
        },
        methods: {
            getList() {
                this.request({
                    url: this.urlobj.url,
                    data: this.urlobj.params
                }).then(resutl => {
                    // console.log(resutl);
                    if (resutl.res.videowp.length === 0) {
                        this.hasMore = false;
                        unit.showToast({
                            title: "没有更多数据了",
                            icon: "none"
                        });
                        return;
                    }
                    this.videolist = [...this.videolist, ...resutl.res.videowp];
                    console.log(this.videolist)
                })
            },
            handleToLower() {
                if (this.hasMore) {
                    this.urlobj.params.skip += this.urlobj.params.limit;
                    this.getList()
                }else {
                    uni.showToast({
                        title: "没有更多数据了",
                        icon: "none"
                    })
                }
            },
            handleGoVideo(item,i) {
                getApp().globalData.video = item;
                // 页面转跳
                uni.navigateTo({
                    url: "/pages/videoPlay/index"
                })
            }
        }
    }
</script>

<style scoped lang="scss">
    .video_main{
        display: flex;
        flex-wrap: wrap;
        height: calc(100vh - 36px);
        .video_item{
            width: 33.33%;
            border: 5rpx solid #fff;
        }
    }

</style>
